{% load i18n %}
{% load difftags %}
{% load djblets_deco %}
{% load djblets_utils %}
{% if standalone and error %}
{{error}}
{% endif %}
{% if file.changed_chunks %}
{% if not standalone %}
<table class="sidebyside{% if not file.interfilediff and file.newfile %} newfile{% endif %}" id="file{{file.filediff.id}}">
 <colgroup>
  <col class="line" />
  <col class="left" />
  <col class="line" />
  <col class="right" />
 </colgroup>
 <thead>
  <tr onClick="gotoAnchor('{{file.index}}');">
   <th colspan="4"><a name="{{file.index}}" class="file-anchor"></a>{{ file.depot_filename }}</th>
  </tr>
  <tr>
   <th colspan="2" class="rev">{{file.revision}}</th>
   <th colspan="2" class="rev">{{file.dest_revision}}</th>
  </tr>
 </thead>
{% endif %}
{% if file.binary %}
 <tbody class="binary">
  <tr>
   <td colspan="4">{% trans "This is a binary file. The content cannot be displayed." %}</td>
  </tr>
 </tbody>
{% else %}
{% for chunk in file.chunks %}
{%  if not chunk.collapsable or not collapseall %}
 <tbody id="chunk{{file.index}}.{{chunk.index}}"{% ifnotequal chunk.change "equal" %} class="{{chunk.change}}"{% else %}{% if chunk.collapsable %} class="collapsable"{% endif %}{% endifnotequal %}>
{% for line in chunk.lines %}
  <tr line="{{line.0}}"{% ifnotequal chunk.change "equal" %}{% attr "class" %}{% if forloop.first %}first{% endif %} {% if forloop.last %}last{% endif %}{% endattr %}{% endifnotequal %}>
{% if forloop.first %}
   <th>{% ifnotequal chunk.change 'equal' %}<a name="{{file.index}}.{{chunk.index}}" class="chunk-anchor"></a>{% endifnotequal %}{{line.1}}</th>
{% else %}
   <th>{{line.1}}</th>
{% endif %}
{% ifequal chunk.change "replace" %}
   <td><pre>{{ line.2|highlightregion:line.3|showextrawhitespace }}</pre></td>
   <th>{{line.4}}</th>
   <td><pre>{{ line.5|highlightregion:line.6|showextrawhitespace }}</pre></td>
{% else %}
   <td><pre>{{ line.2|showextrawhitespace }}</pre></td>
   <th>{{line.4}}</th>
   <td><pre>{{ line.5|showextrawhitespace }}</pre></td>
{% endifequal %}
  </tr>
{% endfor %}
 </tbody>
{% else %}
 <tbody class="collapsed" id="collapsed-chunk{{file.index}}.{{forloop.counter0}}">
  <tr>
   <th>...</th>
   <td colspan="3">{{ chunk.numlines }} line{{chunk.numlines|pluralize}} hidden [<a href="#" onclick="javascript:expandChunk('file{{file.index}}', '{{file.filediff.id}}', '{{forloop.counter0}}', this); return false;">{% trans "Expand" %}</a>]</td>
  </tr>
 </tbody>
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% if not standalone %}
</table>
<script type="text/javascript">
  $(document).ready(function() {
{% if file.changed_chunks %}
    /* Add to the change index. */
    $("li.change_file_{{file.index}}").html(
      {% include_as_string "diffviewer/changeindex_entry.html" %});
{% else %}
    $("li.change_file_{{file.index}}").remove();
{% endif %}
  });
</script>
{% endif %}
